<?php

/**
 * @Notes: 错误信息
 * @User: chenping
 * @email: 375129701@qq.com
 * @param string $msg
 * @param string $data
 * @return array
 */
function error($msg = '', $data = '')
{
    return [
        "code" => 0,
        "msg" => $msg,
        "data" => $data
    ];
}

/**
 * @Notes: 成功信息
 * @User: chenping
 * @email: 375129701@qq.com
 * @param string $msg
 * @param string $data
 * @return array
 */
function success($msg = '', $data = '')
{
    return [
        "code" => 1,
        "msg" => $msg,
        "data" => $data
    ];
}

/**
 * @Notes:获取配置
 * @User: chenping
 * @email: 375129701@qq.com
 * @param $configFile
 * @return mixed
 */
function getConfig($configFile = '')
{
    if (is_string($configFile)) {
        if ('.' == substr($configFile, -1)) {
            $data = include "config/" . $configFile . 'php';
            return $data;
        } else {
            $d = explode(".", $configFile);
            $data = include "config/" . $d[0] . '.php';
            unset($d[0]);
            if ( $d )return getArr($data,$d);
            return $data;
        }
    }
}

/**
 * @Notes:递归获取数组数据
 * @User: chenping
 * @email: 375129701@qq.com
 * @param $arr
 * @param $index
 */
function getArr($arr,$index)
{
    $data = [];
    foreach ($index as $v){
        if(isset($arr[$v])){
            if(is_array($arr[$v])){
                $data = $arr[$v];
                getArr($data,$index);
            }else{
                 $data = $arr[$v];
            }
        }
    }
    return $data;
}

